home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / LIB51 / XTOI.C < prev   
Text File  |  1997-01-12  |  736b  |  25 lines

  1. /*
  2. ** xtoi -- convert hex string to integer nbr
  3. **         returns field size, else ERR on error
  4. */
  5. xtoi(hexstr, nbr) char *hexstr; int *nbr; {
  6.   int d, b;  char *cp;
  7.   d = *nbr = 0; cp = hexstr;
  8.   while(*cp == '0') ++cp;
  9.   while(1) {
  10.     switch(*cp) {
  11.       case '0': case '1': case '2':
  12.       case '3': case '4': case '5':
  13.       case '6': case '7': case '8':
  14.       case '9':                     b=48; break;
  15.       case 'A': case 'B': case 'C':
  16.       case 'D': case 'E': case 'F': b=55; break;
  17.       case 'a': case 'b': case 'c':
  18.       case 'd': case 'e': case 'f': b=87; break;
  19.        default: return (cp - hexstr);
  20.       }
  21.     if(d < 4) ++d; else return (ERR);
  22.     *nbr = (*nbr << 4) + (*cp++ - b);
  23.     }
  24.   }
  25.